﻿using System.Web.Mvc;
using Data.Domain;
using Data.Repositories;

namespace Web.Controllers
{
    public class HomeController : Controller
    {
        private readonly IRepository<Player> playerRepository;

        public HomeController()
        {
        }

        public HomeController(IRepository<Player> playerRepository)
        {
            this.playerRepository = playerRepository;
        }

        public ActionResult Index()
        {
            var allPlayers = playerRepository.GetAll();
            return View(allPlayers);
        }

        public ActionResult Edit(int id)
        {
            var player = playerRepository.GetById(id);
            return View(player);
        }

        public ActionResult UpdatePlayer(int id)
        {
            var player = playerRepository.GetById(id);
            UpdateModel(player);
            return RedirectToAction("Index");
        }
    }
}
